axios.interceptors.request.use(req=>{
    req.headers.accesstoken=localStorage.getItem("accessToken");
    return req;
})
axios.interceptors.response.use(resp=>{
    if (resp.headers.accesstoken!=null){
        localStorage.setItem("accessToken",resp.headers.accesstoken)
    }
    return resp;
})


new Vue({
    el:"#app",
    data:{
        accounts:[],
        newAccount:{
            accountPhone:""
        },
        addAccountWindow: false,
        updateObj:{},
        updatePowerObj:{},
        showPowerWindow:false,
        powerLevel:[
            {
                value: 2,
                label:'审核注册员',
            },{
                value: 3,
                label:'类别管理员',
            },{
                value: 4,
                label:'普通员工',
            }
        ]
    },
    methods: {
        loadAllAccounts(){
            axios.get("/account/list").then(resp=>{
                console.log(resp)
                this.accounts = resp.data.data
            })
        },
        addAccount(){
            axios.post("/account/insert",this.newAccount).then(resp=>{
                alert(resp.data.message)
                this.loadAllAccounts()
                this.newAccount.accountPhone=""
                this.addAccountWindow=false
                this.loadAllAccounts()
            })
        },updateState(obj,num){
            let objstr = JSON.stringify(obj)
            this.updateObj = JSON.parse(objstr)
            this.updateObj.accountState=num;
            axios.post("/account/updateState",this.updateObj).then(resp=>{
                alert(resp.data.message)
                this.loadAllAccounts()
            })
        },updatePower(obj){
            let objstr = JSON.stringify(obj)
            this.updatePowerObj = JSON.parse(objstr)
            this.showPowerWindow=true
        },
        authorization(){
            axios.post("/account/authorization",this.updatePowerObj).then(resp=>{
                alert(resp.data.message)
                this.showPowerWindow=false
                this.loadAllAccounts()
            })
        },handleClose1(){
            this.showPowerWindow=false
        }

    },
    created(){
        this.loadAllAccounts()
    }
})